package com.zmn.oms.services.impl.chan;

import com.zmn.oms.model.entity.chan.OrderClue;
import com.zmn.oms.persistence.interfaces.chan.OrderClueDAO;
import com.zmn.oms.services.interfaces.chan.OrderClueService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * 类描述：
 *
 * @author lhl
 * @date 2020/12/29 15:29
 */
@Service("orderClueService")
public class OrderClueServiceImpl implements OrderClueService {

    @Resource
    private OrderClueDAO orderClueDAO;


    @Override
    public OrderClue findByKey(Long key) {
        if (key == null) {
            return null;
        }
        return orderClueDAO.findByKey(key);
    }

    @Override
    public OrderClue findByFacadeIdAndOuterId(Integer facadeId, String outerId, Integer channelId) {
        if (facadeId == null || StringUtils.isBlank(outerId)) {
            return null;
        }
        return orderClueDAO.findByFacadeIdAndOuterId(facadeId, outerId, channelId);
    }

    @Override
    public OrderClue findByFacadeOrderId(Long facadeOrderId) {
        if (facadeOrderId == null) {
            return null;
        }
        return orderClueDAO.findByFacadeOrderId(facadeOrderId);
    }

    @Override
    public OrderClue findByZmnOrderId(Long zmnOrderId) {
        if (zmnOrderId == null) {
            return null;
        }
        return orderClueDAO.findByZmnOrderId(zmnOrderId);
    }

    @Override
    public int save(OrderClue orderClue) {
        if (orderClue == null) {
            return 0;
        }
        return orderClueDAO.insert(orderClue);
    }

    @Override
    public int updateZmnOrderIdByKey(Long key, Long zmnOrderId, Integer state) {
        if (key == null || zmnOrderId == null || state == null) {
            return 0;
        }
        return orderClueDAO.updateZmnOrderIdByKey(key, zmnOrderId, state);
    }

    @Override
    public int updateStateByKey(Long key, Integer state) {
        if (key == null || state == null) {
            return 0;
        }
        return orderClueDAO.updateStateByKey(key, state);
    }

    @Override
    public int updateMessageNoByKey(Long key) {
        if (key == null) {
            return 0;
        }
        OrderClue orderClue = new OrderClue();
        orderClue.setId(key);
        int i = orderClueDAO.updateMessageNoByKey(orderClue);
        return i == 1 ? orderClue.getMessageNo() : 0;
    }
}
